/**
 * Promise的类方法 - any
 * ES12新增语法
 */
//console.log(Object.getOwnPropertyDescriptors(Promise))
const p1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    // resolve('1111')
    reject('p1 reject error')
  }, 1000)
})
const p2 = new Promise((resolve, reject) => {
  setTimeout(() => {
    // resolve('2222')
    reject('p2 reject error')
  }, 2000)
})
const p3 = new Promise((resolve, reject) => {
  setTimeout(() => {
    // resolve('3333')
    reject('p3 reject error')
  }, 500)
})

//等到第一个fulfilled状态才停止，如果全是rejected，则要等所有reject完成后才停止，catch将会收集所有的err，放到errors属性中
Promise.any([p1, p2, p3])
  .then((res) => {
    console.log(res)
  })
  .catch((err) => {
    console.log(err) //AggregateError: All promises were rejected
    console.log(err.errors) //["p1 reject error", "p2 reject error", "p3 reject error"]
  })
